function Key() {
  this.isPressed = false
  this.justPressed = false
  this.justReleased = false
}

Key.prototype.isPressed = isPressed
Key.prototype.justPressed = justPressed
Key.prototype.justReleased = justReleased
Key.prototype.update = update
Key.prototype.set = set

Key.KEY_DOWN = 0
Key.KEY_UP = 1

function update(action) {
  this.justPressed = false
  this.justReleased = false

  if (action === 0) {
    if (!this.isPressed) {
      this.justPressed = true
    }

    this.isPressed = true
  } else {
    if (this.isPressed) {
      this.justReleased = true
    }

    this.isPressed = false
  }
}

function isPressed() {
  return this.isPressed
}

function justPressed() {
  return this.justPressed
}

function justReleased() {
  return this.justReleased
}

function set(justPressed, isPressed, justReleased) {
  this.justPressed = justPressed
  this.isPressed = isPressed
  this.justReleased = justReleased
}
